

export const DEFAULT_VALUE = {
  ARRAY: "[]",
  OBJECT: "{}",
  STRING: "",
}

export const localStorageFactory = (params) => {
  const { defaultValue, key, raw = false } = params;
  const setItem = (value) => {
    const data = raw ? value : JSON.stringify(value || defaultValue)
    localStorage.setItem(key, data)
  }
  const removeItem = () => {
    localStorage.removeItem(key)
  }
  const getItem = () => {
    const data = raw ? defaultValue : JSON.parse(localStorage.getItem(key) || defaultValue)
    return data
  }
  return {
    getItem,
    setItem,
    removeItem
  }
}
